package handler

import (
	"sep19-homework/model"
	"strconv"

	"github.com/gin-gonic/gin"
)

func LikeAdd(c *gin.Context) {
	user_id, _ := strconv.Atoi(c.PostForm("user_id"))
	new_id, _ := strconv.Atoi(c.PostForm("new_id"))

	like := model.Like{
		UserId: user_id,
		NewId:  new_id,
	}
	err := model.DB.Create(&like).Debug().Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "点赞失败",
		})
		return
	}

	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "点赞成功",
	})
	return
}
